﻿using Devonline.Core;

var m = 10000;
var n = 30;
var l = 10;
Console.WriteLine($"Run Fibonacci test {m} times for n={n} now!");

Console.WriteLine($"Run Fibonacci test {m} times for n={n} loop test!");
var startTime = DateTime.Now;
for (int i = 0; i < m; i++)
{
    Fibonacci(n);
}

//Console.WriteLine((DateTime.Now - startTime).TotalMilliseconds);
Console.WriteLine(startTime.GetTimeDetail());

m = m * l;
Console.WriteLine($"Run Fibonacci test {m} times for n={n} paralla test!");
startTime = DateTime.Now;
Parallel.For(0, m, x => Fibonacci(n));
//Console.WriteLine((DateTime.Now - startTime).TotalMilliseconds);
Console.WriteLine(startTime.GetTimeDetail());

Console.WriteLine("Run Fibonacci test finished, please press any key to exit!");
Console.ReadKey();

static int Fibonacci(int n)
{
    if (n <= 1)
    {
        return 1;
    }

    return Fibonacci(n - 1) + Fibonacci(n - 2);
}